package com.example.testcamara;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;

public class Camera2Activity extends AppCompatActivity {
    public static final String FILENAME = "FILENAME";
    public static final String ACT = "ACT";
    public static final int TAKE_PIC = 0;
    public static final int RECORDING_VIDEO = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        setContentView(R.layout.activity_camera2);

        ActionBar actionBar = getSupportActionBar();
        actionBar.hide();
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        if (savedInstanceState == null) {
            int act = getIntent().getIntExtra(ACT, 0);
            String fileName = getIntent().getStringExtra(FILENAME);
            FragmentManager manager = getSupportFragmentManager();
            FragmentTransaction transaction = manager.beginTransaction();
            if (act == TAKE_PIC) {
                TakePicFragment takePicFragment = new TakePicFragment();
                takePicFragment.setFileName(fileName);
                transaction.add(R.id.frag_camera, takePicFragment);
            } else {
                RecordVideoFragment recordVideoFragment = new RecordVideoFragment();
                recordVideoFragment.setFileName(fileName);
                transaction.add(R.id.frag_camera, recordVideoFragment);
            }
            transaction.commit();
        }

        Button btnHide = findViewById(R.id.btn_bottom);
        btnHide.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                btnHide.setVisibility(View.GONE);
            }
        });
    }

}